<%@ page language="java" pageEncoding="utf-8" contentType="text/html; charset=utf-8"%>
<%@ taglib prefix="ww" uri="webwork" %>
<ww:bean name="'com.css.apps.base.dict.service.DictMan'" id="dictID" />
<div class="page-header">
  <h5><ww:if test="msgApp.uuid != null">修改第三方应用</ww:if><ww:else>添加第三方应用</ww:else></h5>
</div>
<form class="form-horizontal form-validate" method="post"  id="MsgAddform" <ww:if test="msgApp.uuid != null">action="updMsgApp.action"</ww:if><ww:else>action="addMsgApp.action"</ww:else> 
	 onsubmit="return $action.submit(this)">
<div layoutH="84">
  <input type="hidden" name="uuid" id="uuid" value="<ww:property value='msgApp.uuid'/>">
  <input type="hidden" name="dateInfo" id="dateInfo" value="<ww:property value="new java.text.SimpleDateFormat('yyyy-MM-dd HH:mm:ss').format(msgApp.createdTime)"/>">
  <div class="control-group">
  	
  </div>
  <div class="control-group" >
    <label class="control-label"><span class="required">*</span>应用标识</label>
    <div class="controls">
      <input <ww:if test="msgApp.uuid != null">readonly="readonly"</ww:if>type="text" maxlength="100"  placeholder="请输入应用标识"  class="input-large required ipip" name="appCode" id="appCode" value="<ww:property value='msgApp.appCode'/>" >
    </div>
  </div>
  <div class="control-group" >
    <label class="control-label"><span class="required">*</span>应用名称</label>
    <div class="controls">
      <input type="text" maxlength="100"  placeholder="请输入应用名称"  class="input-large required ipip" name="appName" id="appName" value="<ww:property value='msgApp.appName'/>" >
    </div>
  </div>
  <div class="control-group">
      <label class="control-label"><span class="required">*</span>开启状态</label>
      <div class="controls">
      <select name="openFlag" id="openFlag" class="required input-small" onchange="">
		<ww:iterator value="#dictID.getDictListSel('d_openflag')">
		<option value="<ww:property value="code"/>"
		<ww:if test="msgApp.openFlag == code ">selected</ww:if>>
			<ww:property value="name" />
		</option>
		</ww:iterator>
		</select>
	  </div>
  </div>
  <div class="control-group">
      <label class="control-label"><span class="required">*</span>是否检验IP</label>
      <div class="controls">
      <select name="checkIp" id="checkIp" class="required input-small" onchange="">
		<ww:iterator value="#dictID.getDictListSel('d_truefalse')">
		<option value="<ww:property value="code"/>"
		<ww:if test="msgApp.checkIp == code ">selected</ww:if>>
			<ww:property value="name" />
		</option>
		</ww:iterator>
		</select>
	  </div>
  </div>
  
  <div class="control-group">
      <label class="control-label">允许发送的消息类型</label>
      <div class="controls">
	      <ww:iterator value="#dictID.getDictType('msg_d_msgtype')">
           <label class="checkbox inline">
           		<input type="checkbox"  value="<ww:property value='code'/>" id="checkMsgType" name="checkMsgType" 
          			<ww:if test="msgApp.checkMsgType != null && msgApp.checkMsgType.contains(code)">checked="checked"</ww:if>
          			<ww:if test="code.equals(\"1\")">onclick="emailInfo(this);"</ww:if>><ww:property value="name"/>
          	</label>
	      </ww:iterator>
      </div>
  </div>
  <div id = "emailInfo" <ww:if test="msgApp.checkMsgType==null || !msgApp.checkMsgType.contains(\"1\")">style="display: none;"</ww:if>>
  <div class="control-group" >
    <label class="control-label"><span class="required">*</span>smtp地址</label>
    <div class="controls">
      <input type="text" maxlength="100"  placeholder="请输入smtp地址"  class="input-large ipip" name="mailSmtpHost" id="mailSmtpHost" value="<ww:property value='mailSmtpHost'/>" >
    </div>
  </div>
  
  <div class="control-group" >
    <label class="control-label"><span class="required">*</span>邮箱用户名</label>
    <div class="controls">
      <input type="text" maxlength="100"  placeholder="请输入邮箱名称"  class="input-large ipip" name="mailUser" id="mailUser" value="<ww:property value='mailUser'/>" >
    </div>
  </div>
  
  <div class="control-group" >
    <label class="control-label"><span class="required">*</span>邮箱密码</label>
    <div class="controls">
      <input type="password" maxlength="100"  placeholder="请输入邮箱密码"  class="input-large ipip" name="mailPassword" id="mailPassword" value="<ww:property value='mailPassword'/>" >
    </div>
  </div>
  </div>

  <div class="control-group">
    <label class="control-label"><span>&nbsp;</span><span>&nbsp;</span>合法IP配置</label>
	<div class="controls">
		<input id="ipInput" class="ipInput" type="text" maxlength="100"  placeholder="请输入合法IP" >
	  <div class="msgcenter" style="position: relative;top: -25px;left: 230px;width:50px;height: 10px;">
      	<span class="button add" title="新增" onclick="addIp();"></span>
      	<span class="button remove" title="删除" onclick="delIp();"></span>
      </div>
      <div>
	      <select id="ips" name="ips" multiple="multiple" size="5">
			<ww:iterator value="msgApp.getIpListObj()">
				<option value="<ww:property value="appSysIp"/>"><ww:property value="appSysIp" /></option>
			</ww:iterator>
			</select>
      </div>
    </div>
  </div>
</div>
  <div class="set-btn" data-spy="affix" data-offset-top="200">
   <button class="btn save" type="button" href="javascript:;" onclick="submitMsgApp(this);">提交</button>
   <a class="btn" href="javascript:;" target="closeTab">取消</a>
  </div>
</form>
<script>

function emailInfo(obj){
	var $tab = $.cssTab.focus();
	if(obj.checked==true){
		$("#emailInfo",$tab).show();
		$("#mailSmtpHost",$tab).addClass("required");
		$("#mailUser",$tab).addClass("required");
		$("#mailPassword",$tab).addClass("required");
	}else{
		$("#emailInfo",$tab).hide()
		$("#mailSmtpHost",$tab).removeClass("required");
		$("#mailUser",$tab).removeClass("required");
		$("#mailPassword",$tab).removeClass("required");
	}
}

/*
 * 此处应验证ip合法
 */
function addIp(){
	var $tab = $.cssTab.focus();
	var reg=/^(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])\.(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])\.(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])\.(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])$/;
	var ipInput = $("#ipInput",$tab).val()
	if(!reg.test(ipInput)){
		$css.alert('请输入合法ip！');	
		return;
	}
	if($('#ips option[value="'+ipInput+'"]',$tab).size()>0) {
		$css.alert('ip不能重复！');
		return;
	}
	$("#ips",$tab).append("<option value='" + ipInput + "'>" + ipInput + "</option>"); 
}
function delIp(){
	var $tab = $.cssTab.focus();
	$("#ips option:selected",$tab).remove();
}
function submitMsgApp(t){
	var $tab = $.cssTab.focus();
	$("#ips option", $tab).attr("selected", "selected");
	$(t).submit();
}

</script>